﻿window.hcUtils = {
    /*		apiRoot:''  //api 服务器地址前缀
        ,staticRoot:'/static' //静态资源路径前缀，如js,css等
        ,fileUploadApi:'http://test.health-care.vip/file/uploadIconAdmin'  //文件地址api地址
        ,imgRoot:'http://test.health-care.vip/file'  //用户头像图片下载地址前缀
        ,mediaUploaApi:'http://test.health-care.vip/file/uploadCMS'  //多媒体上传API地址
        ,mediaRoot:'http://test.health-care.vip/file'   //多媒体资源下载地址前缀
       //  测试服务器配置，可用如下注释掉的配置
    */
    apiRoot: ''  //api 服务器地址前缀
    , staticRoot: '/style/' //静态资源路径前缀，如js,css等
    , fileUploadApi: 'http://test.health-care.vip/file/uploadIconAdmin'  //文件地址api地址
    , imgRoot: 'http://test.health-care.vip/file'  //用户头像图片下载地址前缀
    , mediaUploaApi: 'http://test.health-care.vip/file/uploadCMS'  //多媒体上传API地址
    , mediaRoot: 'http://test.health-care.vip/file'   /*//多媒体资源下载地址前缀*/
    , getQueryString: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
    , toDateStr: function (nTime) {
        var birthday = new Date(nTime);
        var strBirthDay = birthday.getFullYear() + "-" + (birthday.getMonth() + 1) + "-" + birthday.getDate();
        return strBirthDay;
    }
    , toDateTimeStr: function (nTime) {
        var format = function (n) {
            var szReturn = n;
            if (n < 10) {
                szReturn = "0" + n;
            }
            return szReturn;
        };
        var birthday = new Date(nTime);
        var strBirthDay = birthday.getFullYear() + "-" + (birthday.getMonth() + 1) + "-" + birthday.getDate() + " " + format(birthday.getHours()) +
            ":" + format(birthday.getMinutes()) + ":" + format(birthday.getSeconds());
        return strBirthDay;
    }
    , replaceImgRootUrlInPlaceHolder: function (content) {//在文章保存时将图片服务器域名地址替换为一个变量（$Root$）
        if (content && content.length > 0) {
            content = content.replace(this.mediaUploaApi, "$Root$");
            return content;
        }
        return content;

    }
    , replaceImgPlaceHolder: function (content) {//在文章编辑或查看时将图片服务器域名地址从一个固定变量替换成正式的图片服务器地址（$Root）
        if (content && content.length > 0) {
            content = content.replace("$Root$", this.mediaUploaApi);
            return content;
        }
        return content;
    }
};

jQuery.extend({
    browser: function () {
        var
        rwebkit = /(webkit)\/([\w.]+)/,
        ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/,
        rmsie = /(msie) ([\w.]+)/,
        rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/,
        browser = {},
        ua = window.navigator.userAgent,
        browserMatch = uaMatch(ua);

        if (browserMatch.browser) {
            browser[browserMatch.browser] = true;
            browser.version = browserMatch.version;
        }
        return { browser: browser };
    }
});

function uaMatch(ua) {
    ua = ua.toLowerCase();

    var match = rwebkit.exec(ua)
                || ropera.exec(ua)
                || rmsie.exec(ua)
                || ua.indexOf("compatible") < 0 && rmozilla.exec(ua)
                || [];

    return {
        browser: match[1] || "",
        version: match[2] || "0"
    };
}
//护展方法
$.extend(hcUtils, {
     triggerRadioClick: function () {
        $(":checked").trigger("click");
    }
    //重置表单
    , resetForm: function ($form) {
        var form = $form || $("form:eq(0)");
        if (form.length && form.reset) {
            form[0].reset();
        }
        if ($.fn.combo) { form.find('.combo-f').combo('reset'); }
        if ($.fn.combobox) { form.find('.combobox-f').combobox('reset'); }
        if ($.fn.combotree) { form.find('.combotree-f').combotree('reset'); }
        if ($.fn.combogrid) { form.find('.combogrid-f').combogrid('reset'); }
        if ($.fn.datebox) { form.find('.datebox-f').datebox('reset'); }
        if ($.fn.datetimebox) { form.find('.datetimebox-f').datetimebox('reset'); }
        if ($.fn.spinner) { form.find('.spinner-f').spinner('reset'); }
        if ($.fn.timespinner) { form.find('.timespinner-f').timespinner('reset'); }
        if ($.fn.numberbox) { form.find('.numberbox-f').numberbox('reset'); }
        if ($.fn.numberspinner) { form.find('.numberspinner-f').numberspinner('reset'); }
    }
    //ajax操作通用方法
    , ajaxOperate: function (url, data, cbSuccess, cbFail, cbAlways) {
        var loadIndex = top.layer.load();
        var promise = $.ajax({
            type: "post",
            dataType:"json",
            url: url,
            data: data
        });
        promise.done(function (response) {
            if (!response.IsError) {
                if (cbSuccess) {
                    cbSuccess(response.Data);
                }
            } else {
                cbFail && cbFail(response.Message);
            }
        });
        promise.fail(function (XMLHttpRequest, textStatus, errorThrown) {
            alert("网络通信错误！");
        });
        promise.always(function (XMLHttpRequest, textStatus) {
            cbAlways && cbAlways();
            top.layer.close(loadIndex);
        });
    }
    //根据名称判断控件是否为radio或checkbox
    , checkable: function (name) {
        var ctrls = $("input[name='" + name + "']");
        if (ctrls.length) {
            return (/radio|checkbox/i).test(ctrls[0].type);
        }
        return false;
    }
    //根据名称获取单选按钮的值
    , getRadioVal: function (name) {
        var oReturn = "";
        $(":radio[name='" + name + "']").each(function (i, n) {
            if (this.checked) {
                oReturn = $(this).val();
                return false;
            }
        });
        return oReturn;
    }
    //根据名称获取单选按钮的值
    , setRadioVal: function (name, value) {
        var oReturn = "";
        $(":radio[name='" + name + "']").each(function (i, n) {
            if ($(n).val() == value) {
                $(n).prop("checked", true);
            }
        });
        return oReturn;
    }
    , disableRadio: function (name) {
        $(":radio[name='" + name + "']").prop("disabled", true);
    }

    //安全获取layer控件
    , getLayer: function () {
        var layer = window.layer;
        try {
            layer = top.layer;
        }
        catch(ex) {
            
        }
        return layer;
     }
    , alert: function (msg) {
        var layer = top.layer || window.layer || window;
        layer.alert(msg, { btnAlign: 'c' });
    }
    , confirm: function (msg, ok, cancel,cbSuccess,icon,title) {
        var iconIndex = 1;
        if (icon) {
            iconIndex = icon;
        }
        var titleText = "信息确认";
        if (title) {
            titleText = title;
        }
        var okText = "确认";
        var cancelText = "取消";
        if (ok) {
            okText = ok;
        }
        if (cancel) {
            cancelText = cancel;
        }
        var index = top.layer.open({
            title:titleText,
            content: msg,
            icon: iconIndex,
            btn: [okText, cancelText],
            yes: function (index, layero) {
                closeTopLayer();
                cbSuccess && cbSuccess();
                return true;
            }, btn2: function (index, layero) {
                closeTopLayer();
                return false;
            }
        });
        top.window.currentLayerIndex = index;
        return false;
     }
    , msg: function (msg, cb, seconds) {
        var layer = top.layer || window.layer;
        var time = 2000;
        if (seconds) {
            time = seconds * 1000;
        }
        layer.msg(msg, {
            icon: 1,
            time: time //2秒关闭（如果不配置，默认是3秒）
        }, function () {
            cb && cb();
        });
    }
});

function showPageLayer(titleName, url, mwidth, mheight, otherOpts) {
    mwidth = mwidth || 900;
    //mwidth = Math.max(mwidth, 400);
    mheight = mheight || 550;
    //mheight = Math.max(mheight, 350);
    var settings = {
        type: 2,
        title: titleName,
        maxmin: true,
        //shadeClose: true, //点击遮罩关闭层
        area: [mwidth + 'px', mheight + 'px'],
        content: [url], //[url,'no']
        resize: true //是否允许拉伸
    };
    if (otherOpts && $.isPlainObject(otherOpts)) {
        settings = $.extend(settings, otherOpts);
    }
    var index = layer.open(settings);
    window.currentLayerIndex = index;
    return index;
}
//弹出一个窗口
function showLayer(titleName, url, mwidth, mheight, otherOpts) {
    mwidth = mwidth || 900;
    //mwidth = Math.max(mwidth, 400);
    mheight = mheight || 550;
    //mheight = Math.max(mheight, 350);
    var settings = {
        type: 2,
        title: titleName,
        maxmin: true,
        //shadeClose: true, //点击遮罩关闭层
        area: [mwidth + 'px', mheight + 'px'],
        content: [url], //[url,'no']
        resize: true //是否允许拉伸
    };
    if (otherOpts && $.isPlainObject(otherOpts)) {
        settings = $.extend(settings, otherOpts);
    }
    var index = layer.open(settings);
    window.currentLayerIndex = index;
    return index;
}
//在框架最顶层弹出层
function showTopLayer(titleName, url, mwidth, mheight, otherOpts) {
    mwidth = mwidth || 900;
    //mwidth = Math.max(mwidth, 400);
    mheight = mheight || 550;
    //mheight = Math.max(mheight, 350);
    var settings = {
        type: 2,
        title: titleName,
        maxmin: true,
        //shadeClose: true, //点击遮罩关闭层
        area: [mwidth + 'px', mheight + 'px'],
        content: [url], //[url,'no']
        resize: true //是否允许拉伸
    };
    if (otherOpts && $.isPlainObject(otherOpts)) {
        settings = $.extend(settings, otherOpts);
    }
    var index = top.layer.open(settings);
    top.window.currentLayerIndex = index;
    return index;
}
//关闭最上层的弹出层
function closeTopLayer() {
    top.layer.close(top.window.currentLayerIndex);
}
//关闭所有弹出层
function closeAllLayer(type) {
    if (type) {
        top.layer.closeAll(type);
    }
    else {
        top.layer.closeAll();
    }

}

function getRadioVal(name) {
    var oReturn = "";
    $(":radio[name='" + name + "']").each(function (i, n) {
        if (this.checked) {
            oReturn = $(this).val();
            return false;
        }
    });
    return oReturn;
}

function bindProviceCityDrp(drpProvince, drpCity) {
    var url = siteBaseUrl + "/manage/ajax/api.aspx";
    drpProvince.on("change", function () {
        drpCity[0].length = 1;
        
        $.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            data: {
                action: "getcity",
                provinceid: drpProvince.val()
            },
            success: function (response) {
                if (!response.IsError) {
                    drpCity[0].length = 1;
                    for (var i = 0; i < response.Data.length; i++) {
                        var item = response.Data[i];
                        drpCity.append('<option value="' + item.CityId + '">' + item.CityName + '</option>');
                    }
                } 
            }
        });
    });//end drpProvince
    
}
/**
 * 省市区县联动方法
 * @param {} drpProvince 
 * @param {} drpCity 
 * @param {} drpArea 
 * @returns {} 
 */
function bindProviceCityAreaDrp(drpProvince, drpCity, drpArea) {
    var url = siteBaseUrl + "/manage/ajax/api.aspx";
    drpProvince.on("change", function () {
        drpCity[0].length = 1;
        drpArea[0].length = 1;
        $.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            data: {
                action: "getcity",
                provinceid: drpProvince.val()
            },
            success: function (response) {
                if (!response.IsError) {
                    drpCity[0].length = 1;
                    for (var i = 0; i < response.Data.length; i++) {
                        var item = response.Data[i];
                        drpCity.append('<option value="' + item.CityId + '">' + item.CityName + '</option>');
                    }
                } 
            }
        });
    });//end drpProvince
    drpCity.on("change", function () {
        drpArea[0].length = 1;
        $.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            data: {
                action: "getarea",
                cityId: drpCity.val()
            },
            success: function (response) {
                if (!response.IsError) {
                    drpArea[0].length = 1;
                    for (var i = 0; i < response.Data.length; i++) {
                        var item = response.Data[i];
                        drpArea.append('<option value="' + item.AreaId + '">' + item.AreaName + '</option>');
                    }
                } 
            }
        });
    });
}

function bindBrandSerialCar(drpCarMasterBrand, drpCarSerial, drpCarBasic,masterBrandID,serialID,carBasicID) {
    var url = siteBaseUrl + "/manage/ajax/api.aspx";
    $.ajax({
        type:"post",
        dataType:"json",
        url:url,
        data: {
            action: "GetMasterBrand"
        },
        success:function(response) {
            if (!response.IsError) {
                var data = response.Data;
                for (var i = 0; i < data.length; i++) {
                    var group = data[i];
                    drpCarMasterBrand.append('<optgroup label="' + group.GroupName + '">');
                    var j = 0;
                    for (; j < group.Items.length; j++) {
                        var item = group.Items[j];
                        drpCarMasterBrand.append('<option value="' + item.Value + '">' + item.Text + '</option>');
                    }
                    drpCarMasterBrand.append('</optgroup>');
                }
                if (masterBrandID > 0) {
                    drpCarMasterBrand.find("option[value='" + masterBrandID + "']").attr("selected", "selected");
                    drpCarMasterBrand.trigger("change");
                }
            }
        }
    });
    drpCarMasterBrand.on("change", function () {
        drpCarSerial.empty();
        drpCarBasic.empty();
        drpCarSerial.append('<option value="">全部</option>');
        drpCarBasic.append('<option value="">全部</option>');
        $.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            data: {
                action: "GetCarSerial",
                mbid: drpCarMasterBrand.val()
            },
            success: function (response) {
                if (!response.IsError) {
                    var data = response.Data;
                    for (var i = 0; i < data.length; i++) {
                        var group = data[i];
                        drpCarSerial.append('<optgroup label="' + group.GroupName + '">');
                        var j = 0;
                        for (; j < group.Items.length; j++) {
                            var item = group.Items[j];
                            drpCarSerial.append('<option value="' + item.Value + '">' + item.Text + '</option>');
                        }
                        drpCarSerial.append('</optgroup>');
                    }
                    if (serialID > 0) {
                        drpCarSerial.find("option[value='" + serialID + "']").attr("selected", "selected");
                        drpCarSerial.trigger("change");
                    }
                   
                }
            }
        });
    });//end drpProvince
    drpCarSerial.on("change", function () {
        drpCarBasic.empty();
        drpCarBasic.append('<option value="">全部</option>');
        $.ajax({
            type: "POST",
            url: url,
            dataType: "json",
            data: {
                action: "GetCarBasic",
                csid: drpCarSerial.val()
            },
            success: function (response) {
                if (!response.IsError) {
                    var data = response.Data;
                    for (var i = 0; i < data.length; i++) {
                        var group = data[i];
                        drpCarBasic.append('<optgroup label="' + group.GroupName + '">');
                        var j = 0;
                        for (; j < group.Items.length; j++) {
                            var item = group.Items[j];
                            drpCarBasic.append('<option value="' + item.Value + '">' + item.Text + '</option>');
                        }
                        drpCarBasic.append('</optgroup>');
                    }
                    if (carBasicID > 0) {
                        drpCarBasic.find("option[value='" + carBasicID + "']").attr("selected", "selected");
                    }
                }
            }
        });
    });
 
}
/**
 * 上传图片方法
 * @param {} buttonID 
 * @param {} uploadApi 上传文件接口地址
 * @returns {} 
 */
function ajaxUploadImg(buttonID, uploadApi) {
    $("#" + buttonID).uploadify({
        //Set to false if you do not want the files to automatically upload when they are added to the queue.  If set to false, the upload can be triggered using the upload method.
        'auto': true,
        //The delay in seconds before a completed upload is removed from the queue.
        'removeTimeout': 0.2,
        //按钮额外自己添加点的样式类.upload
        'buttonClass': 'upload',
        //限制文件上传大小
        'fileSizeLimit': '100MB',
        //文件选择框显示
        'fileTypeDesc': '选择图片',
        //文件类型过滤
        'fileTypeExts': '*.jpg;*.png',
        //按钮高度
        'height': '30',
        //按钮宽度
        'width': '100',
        //请求类型
        'method': 'post',
        //是否支持多文件上传
        'multi': false,
        //需要重写的事件
        'overrideEvents': ['onDialogClose', 'onSelectError', 'onUploadError'],
        //队列ID，用来显示文件上传队列与进度
        'queueID': 'fileQueue',
        //队列一次最多允许的文件数，也就是一次最多进入上传队列的文件数
        'queueSizeLimit': 10,
        //上传动画，插件文件下的swf文件
        'swf': siteBaseUrl + '/js/uploadify3.2/uploadify.swf',
        //处理上传文件的服务类
        'uploader': uploadApi,
        //上传文件个数限制
        'uploadLimit': 10,
        //上传按钮内容显示文本
        'buttonText': '图片上传',
        'onFallback': function () {
            alert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。");
        },
        //自定义重写的方法，文件上传错误触发
        'onUploadError': function (file, errorCode, errorMsg, errorString) {
            alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
        },
        //文件选择错误触发
        'onSelectError' : function() {
            alert('The file ' + file.name + ' returned an error and was not added to the queue.');
        },
        //文件队列上传完毕触发
        //'onQueueComplete': heightReset,
        //队列开始上传触发
        ///'onUploadStart': heightFit,
        //单个文件上传成功触发
        'onUploadSuccess': function (file, data, response) {
            var response = eval("(" + data + ")");
                        if (!response.IsError) {
                            var oData = response.Data;
                            var szSrc = oData.HttpImgUrl;
                            var saveUrl = oData.ImgUrl;
                            $("#imgPhoto").attr("src", szSrc);
                            $("#hidImgPhoto").val(saveUrl);
                            $("#divImg").show();
                            $("#hidImgPhoto-error").remove();
                        } else {
                            alert(response.data.message);
                        }
        }

    });
}

/**
 *外呼按钮绑定方法
 * @param {} btn ,一个jquery对象
 * @returns
 */
function bindSendCall(form,btn) {
    if (btn && btn.length && form && form.length) {
        btn.on("click", function () {
            var inputExternalCall = $("input[name='ExternalCallID']");
            if (inputExternalCall.length > 0) {
                inputExternalCall[0].remove();
            }
            var isProcess = btn.attr("data-isProcess", "true");
            if (isProcess=="true") {
                return;// 防止重复发送请求
            }

            var callNum = btn.attr("data-callNum");
            if (!callNum) {
                hcUtils.alert("外呼号码不能为空");
                return;
            }
            var loadIndex = layer.load(0, { skin: 'layer-exteral-call', content: '正在拨打', time: 100000 });
            $.ajax({
                type: "POST",
                url: siteBaseUrl + "/manage/ajax/api.aspx",
                dataType: "json",
                data: {
                    action: "SendCall",
                    callnum: callNum
                },
                success: function(response) {
                    if (!response.IsError) {
                        hcUtils.msg("外呼成功，请留意电话盒来电");
                        var externalCallId = response.Data.ExternalCallID;
                        form.append("<input type='hidden' name='ExternalCallID' value='"+externalCallId+"'/>");
                    } else {
                        hcUtils.alert("外呼失败，原因：" + response.Message);
                    }
                },
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    
                },
                complete:function(XHR, TS) {
                    btn.attr("data-isProcess", "false");
                    layer.close(loadIndex);
                }
            });
        });
    } else {
      //  hcUtils.alert("参数错误");
    }
}
/**
 *重置查询条件
 * @param {} btn ,一个jquery对象
 * @returns
 */
function resetCondition() {
    $(".main_search").find("select").val("");
    $(".main_search").find("input[type='text']").val("");
    //$("form:eq(0)").submit();
}

/**
 *订单价格事件
 * 
 * @returns
 */
function onlyPositiveNumber(obj) {//只能输入正数
    //得到第一个字符是否为负号
    var t = obj.value.charAt(0);
    //先把非数字的都替换掉，除了数字和. 
    obj.value = obj.value.replace(/[^\d\.]/g, '');
    //必须保证第一个为数字而不是. 
    obj.value = obj.value.replace(/^\./g, '');
    //保证只有出现一个.而没有多个. 
    obj.value = obj.value.replace(/\.{2,}/g, '.');
    //保证.只出现一次，而不能出现两次以上 
    obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
    //只能输入小数点后两位
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
    //如果第一位是负号，则不允许添加
    //if (t == '-') {
    //    obj.value = '-' + obj.value;
    //}
    
    if (obj.value == "") {
        obj.value = 0;
    }
    //去除以0开头的整数前边的0
    if (obj.value.indexOf('.') == -1) {
        obj.value = parseFloat(obj.value);
    }
    
    
}
function onlyNumber(obj) {//只能输入数字，可以为负数
    //得到第一个字符是否为负号
    var t = obj.value.charAt(0);
    //先把非数字的都替换掉，除了数字和. 
    obj.value = obj.value.replace(/[^\d\.]/g, '');
    //必须保证第一个为数字而不是. 
    obj.value = obj.value.replace(/^\./g, '');
    //保证只有出现一个.而没有多个. 
    obj.value = obj.value.replace(/\.{2,}/g, '.');
    //保证.只出现一次，而不能出现两次以上 
    obj.value = obj.value.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
    //只能输入小数点后两位
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
    //如果第一位是负号，则允许添加
    if (t == '-') {
        obj.value = '-' + obj.value;
    }
    //if (obj.value == "") {
    //    obj.value = 0;
    //}
}
function setPriceInfo() {
    var oInfo = {
        ConfigPrice: parseFloat($("#spConfigPrice").text()),
        CostPrice: parseFloat($("#spCostPrice").text()),
        DrivingPrice: parseFloat($("#spDrivingPrice").text()),
        ExtraCostPrice: parseFloat($("#txtExtraCostPrice").val()),
        CouponPrice: parseFloat($("#txtCouponPrice").val()),
        DepositPrice: parseFloat($("#txtDepositPrice").val()),
        OrderPrice: parseFloat($("#spOrderPrice").text()),
        NeedPayPrice: parseFloat($("#spNeedPrice").text()),
        PayedPrice: parseFloat($("#spPayedPrice").text()),
        OwePrice: parseFloat($("#spOwePrice").text()),
        BenefitPrice: parseFloat($("#spBenefitPrice").text()),
        AdditionalProfit: parseFloat($("#txtAdditionalProfit").val()),
        placeOrderSource: parseInt($("#hidPlaceOrderSource").val())//订单来源，0：个人下单，1：顾问代下单
    };

    computePrice(oInfo);
    //赋值
    $("#spOrderPrice").text(oInfo.OrderPrice.toFixed(2));
    $("#spNeedPrice").text(oInfo.NeedPayPrice.toFixed(2));
    $("#spPayedPrice").text(oInfo.PayedPrice.toFixed(2));
    $("#spOwePrice").text(oInfo.OwePrice.toFixed(2));
    $("#spBenefitPrice").text(oInfo.BenefitPrice.toFixed(2));
}
function computePrice(oInfo) {
    if (oInfo.placeOrderSource == 1) {
        //订单总额
        oInfo.OrderPrice = oInfo.OrderPrice;
        //应收金额
        oInfo.NeedPayPrice = oInfo.OrderPrice + oInfo.ExtraCostPrice - oInfo.CouponPrice + oInfo.AdditionalProfit;
        //已付金额
        oInfo.PayedPrice = oInfo.PayedPrice;
        //未付金额
        oInfo.OwePrice = oInfo.NeedPayPrice - oInfo.PayedPrice;
        //订单利润
        oInfo.BenefitPrice = oInfo.NeedPayPrice - oInfo.CostPrice;
    } else {
        var orderPrice = 0;
        //当附加工本费为负值的不参与计算
        //if (oInfo.ExtraCostPrice <= 0)
        //{
        //    orderPrice = oInfo.ConfigPrice + oInfo.DrivingPrice + oInfo.AdditionalProfit;
        //}
        //else
        //{
            orderPrice = oInfo.ConfigPrice + oInfo.DrivingPrice + oInfo.ExtraCostPrice + oInfo.AdditionalProfit;
       // }
        //订单总额
        oInfo.OrderPrice =orderPrice;
        //应收金额
        oInfo.NeedPayPrice = orderPrice - oInfo.CouponPrice;
        //已付金额
        oInfo.PayedPrice = oInfo.PayedPrice;
        //未付金额
        oInfo.OwePrice = oInfo.NeedPayPrice - oInfo.PayedPrice;
        //订单利润
        oInfo.BenefitPrice = oInfo.ConfigPrice - oInfo.CouponPrice - oInfo.CostPrice + oInfo.AdditionalProfit;
    }
}
$(document).ready(function() {
    $("#txtExtraCostPrice").on("keyup", function (e) {        
        onlyNumber(this);
        setPriceInfo();
    }).on("focusout", function (e) {
        var thisVal = $.trim($(this).val());
        if (thisVal == "" || thisVal=="-") {
            $(this).val("0");
        }
    });;
  
    $("#txtCouponPrice").on("keyup", function (e) {
        onlyPositiveNumber(this);
        //var needPayPrice = parseFloat($("#spNeedPrice").text());
        //var couponPrice = parseFloat($("#txtCouponPrice").val());
        //if (couponPrice >= needPayPrice) {
        //  this.value= needPayPrice-1;
        //}
        setPriceInfo();
    });
    $("#txtDepositPrice").on("keyup", function (e) {
        onlyPositiveNumber(this);
        setPriceInfo();
    });
    $("#txtAdditionalProfit").on("keyup", function (e) {
        onlyPositiveNumber(this);
        setPriceInfo();
    });
});

function CloseWaitHander(id) {
    var url = siteBaseUrl + "/manage/css/todo/ajax.aspx";
    $.ajax({
        type: "POST",
        url: url,
        dataType: "json",
        data: {
            action: "closewait",
            todoid: id
        },
        success: function (response) {
            if (!response.IsError) {
                $().AjaxManage.MessageOpen("已关闭待办");;setTimeout("window.location.href='list.aspx'", 1000);
            } else {
                hcUtils.alert(response.message);
            }
        }
    });
}

    function ShowCloseOrderInfo(state,closestate)
{
        if (state == 4) {
           
            $("#CloseDiv").css("display","");
        }else
        {
            $("#CloseDiv").css("display","none");
        }
        if (closestate == -1) {
            $("#otherRemark").css("display","");
        }else
        {
            $("#otherRemark").css("display","none");
        }
    }
